#include<iostream>
using namespace std;
const int N = 1e5 + 10;
typedef long long LL;
LL a[N];
int n, q;
int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    cin >> q;
    while(q--)
    {
        LL x, y;
        cin >> x >> y;
        int left = 1, right = n;
        while(left < right)
        {
            //int mid = left + (right - left) / 2;
            int mid = (right + left) / 2;
            if(a[mid] >= x) right = mid;
            else left = mid + 1;
        }
        if(a[left] < x)
        {
            cout << 0 << endl;
            continue;
        }
        int tmp = left;
        left = 1, right = n;
        while(left < right)
        {
            //int mid = left + (right - left + 1) / 2;
            int mid = (left + right + 1) / 2;
            if(a[mid] <= y) left = mid;
            else right = mid - 1;
        }
        if(a[left] > y)
        {
            cout << 0 << endl;
            continue;
        }
        cout << left - tmp + 1<< endl;
    }
    return 0;
}
